//补零
function doHandleMonth(month) {
	var m = month;
	if (month.toString().length == 1) {
		m = "0" + month;
	}
	return m;
}
 
// 格式化日期: yyyy-MM-dd
function formatDate(date) {
	const year = date.getFullYear()
	let month = date.getMonth() + 1
	let day = date.getDate()
	if (month < 10) {
		month = `0${month}`
	}
	if (day < 10) {
		day = `0${day}`
	}
	return (`${year}-${month}-${day}`)
}
// 近X天
export function getDay(day) {
	var today = new Date();
	var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
	today.setTime(targetday_milliseconds);
	var tYear = today.getFullYear();
	var tMonth = today.getMonth();
	var tDate = today.getDate();
	tMonth = doHandleMonth(tMonth + 1);
	tDate = doHandleMonth(tDate);
	return tYear + "-" + tMonth + "-" + tDate;
}

// 近X天
export function getDay1(day) {
	var today = new Date();
	var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
	today.setTime(targetday_milliseconds);
	var tYear = today.getFullYear();
	var tMonth = today.getMonth();
	var tDate = today.getDate();
	tMonth = doHandleMonth(tMonth + 1);
	tDate = doHandleMonth(tDate);
	return tYear + "/" + tMonth + "/" + tDate;
}

// 本月
export function getNowMonth() {
	var today = new Date();
	var tYear = today.getFullYear();
	var tMonth = today.getMonth();
	var tDate = today.getDate();
	tMonth = doHandleMonth(tMonth + 1);
	tDate = "01"
	return tYear + "-" + tMonth + "-" + tDate;
}
 
// 上月日期
export function getLastMonth() {
	const date = new Date()
	const year = date.getFullYear()
	const month = date.getMonth()
	const lastMonthStartDate = formatDate(new Date(year, month - 1, 1))
	const lastMonthEndDate = formatDate(new Date(year, month, 0))
	const lastMonth = []
	lastMonth.push(lastMonthStartDate, lastMonthEndDate)
	return lastMonth
}
